1.3. Running the Project 运行项目

    项目将会被编译,并且进行单元测试

    1. -------------------------------------------------------
    2. T E S T S
    3. -------------------------------------------------------
    4. Running com.example.MyResourceTest
    5. 八月 30, 2014 9:35:06 上午 org.glassfish.grizzly.http.server.NetworkListener sta
    6. rt
    7. INFO: Started listener bound to [localhost:8080]
    8. 八月 30, 2014 9:35:06 上午 org.glassfish.grizzly.http.server.HttpServer start
    9. INFO: [HttpServer] Started.
    10. 八月 30, 2014 9:35:07 上午 org.glassfish.grizzly.http.server.NetworkListener shu
    11. tdownNow
    12. INFO: Stopped listener bound to [localhost:8080]
    13. Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.485 sec
    14. Results :
    15. Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
    16. [INFO] BUILD SUCCESS
    17. [INFO] Total time: 02:21 min
    18. [INFO] Finished at: 2014-08-30T09:35:07+08:00
    19. [INFO] Final Memory: 13M/31M
    20. [INFO] ------------------------------------------------------------------------

    上面可以看看到测试通过,下面我们用标准模式运行项目:

    运行结果如下:

    1. [INFO] Scanning for projects...
    2. [INFO]
    3. [INFO] Using the builder org.apache.maven.lifecycle.internal.builder.singlethrea
    4. ded.SingleThreadedBuilder with a thread count of 1
    5. [INFO]
    6. [INFO] ------------------------------------------------------------------------
    7. [INFO] Building simple-service 1.0-SNAPSHOT
    8. [INFO] ------------------------------------------------------------------------
    9. [INFO]
    10. [INFO] >>> exec-maven-plugin:1.2.1:java (default-cli) @ simple-service >>>
    11. [INFO]
    12. [INFO] <<< exec-maven-plugin:1.2.1:java (default-cli) @ simple-service <<<
    13. [INFO]
    14. 八月 30, 2014 9:36:57 上午 org.glassfish.grizzly.http.server.NetworkListener sta
    15. rt
    16. 八月 30, 2014 9:36:57 上午 org.glassfish.grizzly.http.server.HttpServer start
    17. INFO: [HttpServer] Started.
    18. Jersey app started with WADL available at http://localhost:8080/myapp/applicatio
    19. n.wadl
    20. Hit enter to stop it...

    更多 WADL的内容,请查考

    Chapter 16, WADL Support

    接下来试下与部署在 /myresource 下面的资源的交互。将资源的URL输入浏览器,或者在控制台用curl命令执行(译者注:如果没有安装curl,请参考):

    -i命令获取所有回应的头文件信息:

    1. $ curl -i http://localhost:8080/myapp/myresource
    2. HTTP/1.1 200 OK
    3. Content-Type: text/plain
    4. Date: Sat, 30 Aug 2014 02:23:25 GMT
    5. Content-Length: 7
    6. Got it!

    注意到Content-Type: text/plain是在 MyResource 类中用@Produces 注解的。

    如果想看到更多返回信息,可以变换不同的 curl 命令参数。举例: